package com.rice.riceaiagent.rag;

import com.alibaba.cloud.ai.advisor.DocumentRetrievalAdvisor;
import com.alibaba.cloud.ai.dashscope.api.DashScopeApi;
import com.alibaba.cloud.ai.dashscope.rag.DashScopeDocumentRetriever;
import com.alibaba.cloud.ai.dashscope.rag.DashScopeDocumentRetrieverOptions;
import org.springframework.ai.chat.client.advisor.api.Advisor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 简历辅导大师云知识库配置类
 * @author ricejosn
 */
@Configuration
public class ResumeAppRagCloudConfig {
    @Value("${spring.ai.dashscope.api-key}")
    private String dashScopeApiKey;

    @Bean
    public Advisor resumeAppCloudAdvisor() {
        // 创建API
        DashScopeApi dashScopeApi = new DashScopeApi(dashScopeApiKey);
        // 自定义文档检索器
        final String KNOWLEDGE_NAME = "简历辅导大师";
        DashScopeDocumentRetriever documentRetriever = new DashScopeDocumentRetriever(dashScopeApi, DashScopeDocumentRetrieverOptions.builder()
                // 指定知识库名称
                .withIndexName(KNOWLEDGE_NAME)
                .build());
        // 创建Advisor
        return new DocumentRetrievalAdvisor(documentRetriever);
    }
}
